package com.ldj.hibernate;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.Query;

import com.ldj.struts.form.FunctionMenuForm;
import com.ldj.struts.form.SuperviseOrganForm;

public class FunctionMenuDAO extends BaseHibernateDAO {
	public FunctionMenuDAO(HttpServletRequest request, HttpServletResponse response) {
		super(request, response);
		// TODO Auto-generated constructor stub
	}

	private static final Log log = LogFactory.getLog(FunctionMenuDAO.class);
	
	public List findListFromCode(String code) {
		try {
			String queryString = "from FunctionMenu where functionMenuCode like '" + code + "___'";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}
	
	public FunctionMenu findFromCode(String code) {
		try {
			String queryString = "from FunctionMenu where functionMenuCode='" + code + "'";
			Query queryObject = getSession().createQuery(queryString);
			List list = queryObject.list();
			if(list != null && list.size() > 0)
				return (FunctionMenu)list.get(0);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
		return null;
	}
	
	 public List findAllPage(String code) {
			try {
				String queryString =(new StringBuilder("from FunctionMenu where functionMenuCode like '")).append(code).append("___'").toString();
				queryString +="order by functionMenuCode";
				Query queryObject = getSession().createQuery(queryString);
				this.setPageSize(12);
				return this.jlist(queryObject);
			} catch (RuntimeException re) {
				log.error("find all failed", re);
				throw re;
			}
		}
	 public List getSonMenu(String code)
	    {
	        log.debug("finding all FunctionMenu instances");
	        try
	        {
	        	String queryString = "from FunctionMenu where functionMenuCode like '"+code+"___' order by functionMenuCode ";
	            Query queryObject = getSession().createQuery(queryString);
	            return queryObject.list();
	        }
	        catch(RuntimeException re)
	        {
	            log.error("find all failed", re);
	            throw re;
	        }
	    }
	 
	 public List getSonCatalog(String code)
	    {
	        log.debug("finding all FunctionMenu instances");
	        try
	        {
	        	String queryString = "from FunctionMenu where functionMenuCode like '"+code+"%' order by functionMenuCode ";
	            Query queryObject = getSession().createQuery(queryString);
	            return queryObject.list();
	        }
	        catch(RuntimeException re)
	        {
	            log.error("find all failed", re);
	            throw re;
	        }
	    }
	 
	 public List getSonCatalog(String code, String value)
	    {
	        log.debug("finding all FunctionMenu instances");
	        try
	        {
	        	String queryString = "from FunctionMenu where functionMenuCode like '"+code+"___' and functionMenuCode in ('" + value + "') order by functionMenuCode ";
	            Query queryObject = getSession().createQuery(queryString);
	            return queryObject.list();
	        }
	        catch(RuntimeException re)
	        {
	            log.error("find all failed", re);
	            throw re;
	        }
	    }
	 
	 public FunctionMenu findById(java.lang.String id) {
			log.debug("getting FunctionMenu instance with id: " + id);
			try {
				FunctionMenu instance = (FunctionMenu) getSession().get(
						"com.ldj.hibernate.FunctionMenu", id);
				return instance;
			} catch (RuntimeException re) {
				log.error("get failed", re);
				throw re;
			}
		}
	 
	 public FunctionMenu merge(FunctionMenu detachedInstance) {
			try {
				FunctionMenu result = (FunctionMenu) getSession().merge(detachedInstance);
				log.debug("merge successful");
				return result;
			} catch (RuntimeException re) {
				log.error("merge failed", re);
				throw re;
			}
		}
	 
	 public void save(FunctionMenu transientInstance) {
			log.debug("saving FunctionMenu instance");
			try {
				getSession().save(transientInstance);
				log.debug("save successful");
			} catch (RuntimeException re) {
				log.error("save failed", re);
				throw re;
			}
		}
	 
	 public void delete(FunctionMenu transientInstance) {
			log.debug("deleting FunctionMenu instance");
			try {
				getSession().delete(transientInstance);
				log.debug("delete successful");
			} catch (RuntimeException re) {
				log.error("delete failed", re);
				throw re;
			}
		}
	 
	 public List findByCode(String code) {
			log.debug("getting FunctionMenu instance with code: " + code);
			try {
				String queryString = "from FunctionMenu where functionMenuCode like '" + code + "%'";
				Query queryObject = getSession().createQuery(queryString);
				return queryObject.list();
			} catch (RuntimeException re) {
				log.error("find all failed", re);
				throw re;
			}
		}
	 //地区范围
	 public List findByUserId(String pid) {
			log.debug("getting UserAreaScope instance with pid: " + pid);
			try {
				String queryString = "from UserAreaScope where userAreaScopeUserId = '" + pid + "'";
				Query queryObject = getSession().createQuery(queryString);
				return queryObject.list();
			} catch (RuntimeException re) {
				log.error("find all failed", re);
				throw re;
			}
		}
	 
	 public UserAreaScope mergeArea(UserAreaScope detachedInstance) {
			try {
				UserAreaScope result = (UserAreaScope) getSession().merge(detachedInstance);
				log.debug("merge successful");
				return result;
			} catch (RuntimeException re) {
				log.error("merge failed", re);
				throw re;
			}
		}
	 
	 public void deleteArea(UserAreaScope transientInstance) {
			log.debug("deleting UserAreaScope instance");
			try {
				getSession().delete(transientInstance);
				log.debug("delete successful");
			} catch (RuntimeException re) {
				log.error("delete failed", re);
				throw re;
			}
		}
	 
	 public void saveArea(UserAreaScope transientInstance) {
			log.debug("saving UserAreaScope instance");
			try {
				getSession().save(transientInstance);
				log.debug("save successful");
			} catch (RuntimeException re) {
				log.error("save failed", re);
				throw re;
			}
		}
	
}